package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.generator.dao.AuditDao;
import io.renren.modules.generator.entity.AuditEntity;
import io.renren.modules.generator.service.AuditService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Objects;


@Service("auditService")
public class AuditServiceImpl extends ServiceImpl<AuditDao, AuditEntity> implements AuditService {

    @Autowired
    AuditDao auditDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<AuditEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("rest_id", params.get("userId"));
        if (StringUtils.isNotBlank(params.get("auditStatus").toString()) && Objects.nonNull(params.get("auditStatus"))) {
            wrapper.eq("audit_status", params.get("auditStatus"));
        }
        IPage<AuditEntity> page = this.page(
                new Query<AuditEntity>().getPage(params), wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public IPage<Map<String, Object>> selectTeacherAuditList(Page<Map<String, Object>> page, Map<String, Object> params) {
        return auditDao.selectTeacherAuditList(page, params);
    }

    @Override
    public IPage<Map<String, Object>> selectSecretaryAuditList(Page<Map<String, Object>> page, Map<String, Object> params) {
        return auditDao.selectSecretaryAuditList(page, params);
    }

    @Override
    public IPage<Map<String, Object>> allStudentAuditList(Page<Map<String, Object>> page, Map<String, Object> params) {
        return auditDao.allStudentAuditList(page, params);
    }

    @Override
    public IPage<Map<String, Object>> studentRestList(Page<Map<String, Object>> page, Map<String, Object> params) {
        return auditDao.studentRestList(page, params);
    }

}
